export const getToken = () => {
  return localStorage.getItem('token')
}

export const isTokenValid = () => {
  const tokenExpires = localStorage.getItem('tokenExpires')
  if (!tokenExpires) return false
  
  return new Date().getTime() < parseInt(tokenExpires)
}

export const clearAuth = () => {
  localStorage.removeItem('token')
  localStorage.removeItem('tokenExpires')
  localStorage.removeItem('user')
}

export const setAuth = (token, user, expiresIn = 20) => {
  const expiresAt = new Date().getTime() + expiresIn
  localStorage.setItem('token', token)
  localStorage.setItem('tokenExpires', expiresAt.toString())
  localStorage.setItem('user', JSON.stringify(user))
}
